import { defineStore } from "pinia";
import { nextTick } from "vue";
import { Local } from "@/utils/storage";
export const useLayoutConfigStore = defineStore("layoutConfig", {
  state: () => {
    return {
      // 是否折叠起菜单：true折叠，false展开
      isCollapse: false,
      // 网站主标题
      globalTitle: "梦学谷-Vue3全家桶项目",
      isFullscreen: false, // 是否全屏状态：true是
      isDrak: false, // 是否暗黑主题：true是
    };
  },
  getters: {},
  actions: {
    // 持久化保存state值
    updateState(state: LayoutConfigState) {
      // 跟新事件
      this.$patch(state);
    },
  },
});
// pinia监听数据的固定写法
nextTick(() => {
  const layoutConfig = useLayoutConfigStore ();
  layoutConfig.$subscribe((mutation, state) => {
    // 保存到浏览器的localstorage中
    Local.set('layoutConfig',state);
  });
});
